const {
    comMysql
  } = require("../db/mysql")

 const addCollect = (req,res)=>{
     let {username,blogId,blogName} = req.body
     let time = new Date().getTime()
     let sql = `insert into collect(username,collectTime,blogId,blogName) values(?,?,?,?)`
     let arr = [username,time,blogId,blogName]
     return comMysql(sql,arr)
 }
 const deleteCollect = (req,res)=>{
     let {blogId,username} = req.body
     let sql = `delete from collect where blogId = ? and username = ?`
    let arr = [blogId,username]
    return comMysql(sql,arr)
 }
const searchCollect = (req,res)=>{
    let {username,blogId} = req.query
    let sql,arr
    if(blogId){
        sql = `select * from collect where username = ? and blogId = ?`
         arr = [username,blogId]
    }else{
         sql = `select * from collect where username = ?`
         arr = [username]
    }
    
    return comMysql(sql,arr)
}

module.exports = {
    addCollect,
    deleteCollect,
    searchCollect
  }